<!DOCTYPE html>
<html class="um landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link rel="stylesheet" type="text/css" href="skin/base.css">
<link rel="stylesheet" type="text/css" href="skin/post_pub.css">
<script src="js/zy_control.js"></script>
<script src="js/zy_json.js"></script>
<script src="js/zy_click.js"></script>
<script src="js/login.js"></script>
<script src="js/config.js"></script>
<script src="js/common.js"></script>
</head>
<body>
<div id="main">
	<div class="inputdiv">
		<input id="title" placeholder="请在此输入标题" type="text">
	</div>
	<menu ontouchstart="zy_touch('down')" onclick="selectCatalog()">
		<strong id="catalogName">选择分类-提问</strong>
		<input id="catalog" type="hidden" name="catalog" value="1"/>
	</menu>
	<div class="textareadiv">
		<textarea id="content" name="text" placeholder="请在此输入详细描述"></textarea>
	</div>
</div>
</body>
<script>
	zy_init();	
	var Users= new Users({});
	
	function Login(){
		Users.logout();
		localStorage['login']='post_pub';
		uexWindow.open('login', '0', 'login.html', 4, '', '', 0x0);
	}
	
	function selectCatalog(){
		uexWindow.cbActionSheet=function(opId,dataType,data){
			var catalogName = '提问';
			var catalog = '1';
			switch(parseInt(data)) //兼容真机和模拟器
			{
			case 0:
				catalogName = '提问';
				catalog = '1';
			  	break;
			case 1:
				catalogName = '分享';
				catalog = '2';
			  	break;
			case 2:
				catalogName = '综合';
				catalog = '3';
			  	break;
			case 3:
				catalogName = '职业';
				catalog = '100';
			  	break;
			case 4:
				catalogName = '站务';
				catalog = '4';
			  	break;
			case 5:
				status = 0;
				break;
			}
			if(data != 5){
				setValue('catalog', catalog);
				setHtml('catalogName','选择分类-'+catalogName);	
			}
		}
		uexWindow.actionSheet('选择分类','取消',['提问','分享','综合','职业','站务']);
	}
	
	function gopost(){
		if (!Users.checkUser()) {
			Login();
			return false;
		}
		
		var title = Trim($$('title').value);
		var catalog = $$('catalog').value;
		var content = Trim($$('content').value);

		if (title == '') {
			uexWindow.alert('', '忘写标题了吧～', '关闭');
			return false;
		}
		if (content == '') {
			uexWindow.alert('', '忘写内容了吧～', '关闭');
			return false;
		}
		
		var url = OpenAPI.post_pub+'/?client_id='+OpenAPI.client_id+'&access_token='+localStorage['access_token'];
		uexXmlHttpMgr.open(1,'post',url,"8000");
		uexXmlHttpMgr.setPostData(1,'0','title',title);
		uexXmlHttpMgr.setPostData(1,'0','catalog',catalog);
		uexXmlHttpMgr.setPostData(1,'0','content',content);
		uexXmlHttpMgr.setPostData(1,'0','isNoticeMe',0);
		uexXmlHttpMgr.send(1);
		uexWindow.toast(1, 5, '提交中...', 0);
		//logs(url);
		  
	}
	

	window.uexOnload=function(type){
		if (!type) {
			uexXmlHttpMgr.onData = function(opId, status, data){
				uexWindow.closeToast();
				if (status == 1) {
					data = JSON.parse(data);
					uexXmlHttpMgr.close(opId);
					if (data['error'] == '200') {
						uexWindow.evaluatePopoverScript('post','content','ok_post_pub()');
						uexWindow.evaluateScript('post_pub',0,'uexWindow.close(1)');
					}else {
						uexWindow.toast("0", "5", '发布失败', 1000);
					}
				}else if (status == -1) {
					uexXmlHttpMgr.close(opId);
					uexWindow.toast("0", "5", '提交超时', 1000);
				}
			}
		}
	}
	</script>
</html>